//
//  JEHLeadPageViewController.m
//  SinaNews
//
//  Created by 蒋恩浩 on 15/12/21.
//  Copyright © 2015年 JEH. All rights reserved.
//

#import "JEHLeadPageViewController.h"

@interface JEHLeadPageViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionView *collectionView;

@end

@implementation JEHLeadPageViewController

#pragma mark - memoryManagement
- (void)dealloc {
    
    _delegate = nil;
    [_collectionView release];
    [super dealloc];
}

#pragma mark - viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createCollectionViwe];
}

#pragma mark - createCollectionViwe
- (void)createCollectionViwe {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(self.view.width, self.view.height);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height) collectionViewLayout:layout];
    [_collectionView release];
    [layout release];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.bounces = NO;
    _collectionView.pagingEnabled = YES;
    [_collectionView registerClass:[JEHLeadPageCollectionViewCell class] forCellWithReuseIdentifier:@"JEHLeadPageCollectionViewCellIdentifier"];
    [self.view addSubview:_collectionView];
}

#pragma mark - UICollectionViewDelegateMethod
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    JEHLeadPageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"JEHLeadPageCollectionViewCellIdentifier" forIndexPath:indexPath];
    if (indexPath.item == 0) {
        
        cell.picture.image = [UIImage imageNamed:@"LeadPage1"];
    } else {
        cell.picture.image = [UIImage imageNamed:@"LeadPage2"];
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.item == 1) {
        
        [self pushToNews];
    }
}

#pragma mark - pushToNews
- (void)pushToNews {
    
    JEHNewsViewController *news = [[JEHNewsViewController alloc] init];
    [self.navigationController pushViewController:news animated:YES];
    [news release];
    [self.delegate chooseViewController];
}

@end
























